package com.zqu.controller;

import com.zqu.pojo.LoginUser;
import com.zqu.service.LoginUserService;
import com.zqu.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("loginuser")
public class LoginUserController {
   @Autowired
   private LoginUserService loginUserService;

   @RequestMapping("login")
   @ResponseBody
   public JsonResult userLogin(@RequestBody LoginUser loginUser){
      JsonResult jsonResult = new JsonResult();
      LoginUser resultUser = loginUserService.queryLoginUser(loginUser.getUserName());
      if(resultUser == null){
         jsonResult.setMsg("用户名不存在！");
         jsonResult.setCode(500);
      }else if(loginUser.getUserPassword().equals(resultUser.getUserPassword())){
         jsonResult.setMsg("登录成功！");
         jsonResult.setCode(200);
         jsonResult.setObj(resultUser);
      }
      else{
         jsonResult.setMsg("密码错误！");
         jsonResult.setCode(500);
      }
      return jsonResult;
   }

}
